package com.zhonghui.modlules.product.controller;

import com.zhonghui.common.eshopEnum.ProductEnum;
import com.zhonghui.common.eshopEnum.ShopCommonEnum;
import com.zhonghui.common.eshopUtil.ApiResult;
import com.zhonghui.common.eshopVo.StoreProductQueryVo;
import com.zhonghui.modlules.product.eshopParam.StoreProductQueryParam;
import com.zhonghui.modlules.product.eshopService.StoreProductReplyService;
import com.zhonghui.modlules.product.eshopService.StoreProductService;
import com.zhonghui.modlules.product.eshopVo.ReplyCountVo;
import com.zhonghui.modlules.product.eshopVo.StoreProductReplyQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

@Slf4j
@RestController
@Api(value = "产品模块", tags = "商城:产品模块")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class StoreProductController {

    private final StoreProductService storeProductService;
    private final StoreProductReplyService storeProductReplyService;

    @ApiOperation(value = "获取首页更多产品",notes = "获取首页更多产品")
    @GetMapping("/groom/list/{type}")
    public ApiResult<Map<String,Object>> groomList(@PathVariable Integer type){
        Map<String, Object> map = new LinkedHashMap<>();
        if (ProductEnum.TYPE_1.getValue().equals(type)){
            map.put("list",storeProductService.getList(1,20,ProductEnum.TYPE_1.getValue()));
        }else if (type.equals(ProductEnum.TYPE_2.getValue())){
            map.put("list",storeProductService.getList(1,20,ProductEnum.TYPE_2.getValue()));
        }else if (type.equals(ProductEnum.TYPE_3.getValue())){
            map.put("list",storeProductService.getList(1,20,ProductEnum.TYPE_3.getValue()));
        }else if (type.equals(ProductEnum.TYPE_4.getValue())){
            map.put("list",storeProductService.getList(1,20,ProductEnum.TYPE_4.getValue()));
        }
        return ApiResult.ok(map);
    }

    @ApiOperation(value = "商品列表",notes = "商品列表")
    @GetMapping("/products")
    public ApiResult<Map<String,Object>> products(StoreProductQueryParam storeProductQueryParam){
        return ApiResult.ok(storeProductService.getGoodsListByPage(storeProductQueryParam));
    }

    @ApiOperation(value = "为你推荐",notes = "为你推荐")
    @GetMapping("/products/hot")
    public ApiResult<List<StoreProductQueryVo>> productsHot(StoreProductQueryParam param){
        return ApiResult.ok(storeProductService.getList(param.getPage(),param.getLimit(),
                ShopCommonEnum.IS_STATUS_1.getValue()));
    }

    @ApiOperation(value = "获取产品评论",notes = "获取产品评论")
    @GetMapping("/reply/list/{id}")
    public ApiResult<List<StoreProductReplyQueryVo>> replyList(@PathVariable Long id,
                                                               @RequestParam(value = "page",defaultValue = "1")int page,
                                                               @RequestParam(value = "limit",defaultValue = "10")int limit,
                                                               @RequestParam(value = "type",defaultValue = "0")int type){
        return ApiResult.ok(storeProductReplyService.getReplyList(id,type,page,limit));
    }

    @ApiOperation(value = "获取产品评论数据",notes = "获取产品评论数据")
    @GetMapping("/reply/config/{id}")
    public ApiResult<ReplyCountVo> replyCount(@PathVariable Integer id){
        return ApiResult.ok(storeProductReplyService.getReplyCount(id));
    }
}
